package org.jeecg.modules.app.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.jeecg.modules.app.body.ParamMap;
import org.jeecg.modules.app.utils.ToolUtil;
import org.jeecg.modules.app.utils.encrypt.AesUtils;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Aspect
@Configuration
public class EncodeAspect {

    @Pointcut("@annotation(org.jeecg.modules.app.annotation.Encode)")
    public void logPointCut() {
    }

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object[] args = point.getArgs();
        if (ToolUtil.isNotEmpty(((ParamMap) args[0]))) {
            Map<String, Object> map = ((ParamMap) args[0]);
            for (String key : map.keySet()) {
                ((ParamMap) args[0]).put(key, AesUtils.decrypt_ecb(map.get(key).toString()));
            }
        }
        return point.proceed();
    }
}
